/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pos.dao;

import org.hibernate.Session;
import org.hibernate.Transaction;
import pos.bean.Funcinario;
import pos.connection.ConnectionFactory;

/**
 *
 * @author us
 */
public class CensoDao {
    
    Session session;
    Transaction tx;
    
    
    public void salvar (Funcinario funcinario){
        try{
            session = new ConnectionFactory().getSessionFactory();
            tx = session.beginTransaction();
            session.save(funcinario);
            tx.commit();
            session.close();
            
        }catch(Exception e)
        {
            e.printStackTrace();
            tx.rollback();
            session.close();
        }
    } 
     public void alterar (Funcinario funcinario){
        try{
            session = new ConnectionFactory().getSessionFactory();
            tx = session.beginTransaction();
            session.update(funcinario);
            tx.commit();
            session.close();
            
        }catch(Exception e)
        {
            e.printStackTrace();
            tx.rollback();
            session.close();
        }
    }
     public void excluir (Funcinario funcinario){
        try{
            session = new ConnectionFactory().getSessionFactory();
            tx = session.beginTransaction();
            session.delete(funcinario);
            tx.commit();
            session.close();
            
        }catch(Exception e)
        {
            e.printStackTrace();
            tx.rollback();
            session.close();
        }
    }

    
}
